//
//  CheckDetailController.m
//  WuJieLive
//
//  Created by 张瀚坤 on 2017/11/7.
//  Copyright © 2017年 zhk. All rights reserved.
//

#import "CheckDetailController.h"
#import "MyWalletCell.h"
#import "PayGoldDetailController.h"
#import "IncomeGoldDetailController.h"
#import "AllGoldDetailController.h"
#import "CalendarView.h"

@interface CheckDetailController ()

@property (nonatomic , strong) CalendarView * calendarView;
@property (nonatomic, strong) UIView *contentView;
@property (nonatomic , strong) AllGoldDetailController * allVC;
@property (nonatomic , strong) IncomeGoldDetailController * incomeVC;
@property (nonatomic , strong) PayGoldDetailController * payVC;
@property (nonatomic, strong)UIViewController *currentVC;
@end

@implementation CheckDetailController

-(CalendarView *)calendarView
{
    if (!_calendarView) {
       _calendarView = [[[NSBundle mainBundle]loadNibNamed:@"CalendarView" owner:self options:nil] firstObject];
        _calendarView.backgroundColor = [UIColor clearColor];
        _calendarView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
    }
    return _calendarView;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

-(void)setNavi
{
    self.title = @"金库明细";
    [self.rightBtn setImage:Image(@"icon_nav_日历") forState:(UIControlStateNormal)];
}

-(void)rightBtnAction:(UIButton *)sender
{
    self.calendarView.CalendarViewBlock = ^(NSString *beginSrting, NSString *endString) {
        NSLog(@"\n%@",beginSrting);
    };
    [self.view addSubview:self.calendarView];
}

-(void)setUI
{
    SegementScrollView * view = [[SegementScrollView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 40) andtitleArray:@[@"全部",@"收入",@"支出"]];
    [self.view addSubview:view];
    [self loadChildController];
    view.selectedBlock = ^(NSInteger index) {
        if (index == 0) {
            [self changeControllerFromOldController:self.currentVC toNewController:self.allVC];
        }else if (index == 1)
        {
            [self changeControllerFromOldController:self.currentVC toNewController:self.incomeVC];
        }else
        {
            [self changeControllerFromOldController:self.currentVC toNewController:self.payVC];
        }
    };
}
- (void)loadChildController
{
    self.contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 40, kScreenWidth, kScreenHeight - 40)];
    self.contentView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.contentView];
    
    self.allVC = [AllGoldDetailController new];
    [self.allVC.view setFrame:_contentView.bounds];
    [self addChildViewController:self.allVC];
    
    self.incomeVC = [IncomeGoldDetailController new];
    [self.incomeVC.view setFrame:_contentView.bounds];
    
    self.payVC = [PayGoldDetailController new];
    [self.payVC.view setFrame:_contentView.bounds];
    
    [self.contentView addSubview:self.allVC.view];
    self.currentVC = self.allVC;
}
#pragma mark - 切换viewController
- (void)changeControllerFromOldController:(UIViewController *)oldController toNewController:(UIViewController *)newController {
    [self addChildViewController:newController];
    [self transitionFromViewController:oldController toViewController:newController duration:0.3 options:UIViewAnimationOptionCurveEaseIn animations:^{
        
    } completion:^(BOOL finished) {
        if (finished) {
            [newController didMoveToParentViewController:self];
            [oldController willMoveToParentViewController:nil];
            [oldController removeFromParentViewController];
            _currentVC = newController;
        } else {
            _currentVC = oldController;
        }
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
